package com.example.back.service;

import com.example.back.entity.Like;
import com.example.back.mapper.LikeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class LikeService {
    @Autowired
    private LikeMapper likeMapper;
    public int addLike(Like like)
    {
        return likeMapper.addLike(like);
    }
    public int deleteLike(Integer postId, Integer userId)
    {
        return likeMapper.deleteLike(postId,userId);
    }
    public int updateLike(Like like)
    {
        return likeMapper.updateLike(like);
    }
    public ArrayList<Like> queryLike(Like like)
    {
        return likeMapper.queryLike(like);
    }

    // 查询用户是否已点赞该帖子
    public Like getLikeByUserAndPost(Integer postId, Integer userId) {
        return likeMapper.getLikeByUserAndPost(postId, userId);
    }

    // 统计帖子的点赞数
    public int countLikeByPostId(Integer postId){
        return likeMapper.countLikeByPostId(postId);
    }
    public int countUserLikes(Integer userId){
        return likeMapper.countUserLikes(userId);
    }
}
